package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.Worker;
import com.neuedu.yyzx.service.IWorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 工作人员管理  前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-25
 */
@RestController
@RequestMapping("//worker")
public class WorkerController {
    @Autowired
    IWorkerService workerService;

    @RequestMapping("/list")
    CommonResult list(Page page, Worker worker){
        QueryWrapper queryWrapper = new QueryWrapper();
        if(worker!= null && StringUtils.isNotEmpty(worker.getWorkerName())){
            queryWrapper.like("worker_name",worker.getWorkerName());
        }
        return CommonResult.success(workerService.page(page,queryWrapper)) ;
    }

    @RequestMapping("/add")
    CommonResult add(Worker worker){
        return CommonResult.success( workerService.saveOrUpdate(worker));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer workerId){

        return CommonResult.success(workerService.getById(workerId));
    }

    @RequestMapping("/del")
    CommonResult del(Integer workerId){
        return CommonResult.success(workerService.removeById(workerId));
    }

}
